<?php
 $resultsLimit = 10;
/*
 * Following code will list the first number of bets within requested range.
 */
 
// array for JSON response
$response = array();
 
// include db connect class
require_once __DIR__ . '/db_connect.php';
 
// connecting to db
$db = new DB_CONNECT();

// check for post data
if (isset($_GET["minBet"]) && isset($_GET["maxBet"])) {
	$minBet = $_GET["minBet"];
	$maxBet = $_GET["maxBet"];
 
    // get a product from products table
    $result = mysql_query("SELECT * FROM mmg_bets WHERE value >= $minBet AND value <= $maxBet AND acceptorID IS NULL LIMIT $resultsLimit");
 
    if (!empty($result)) {
        // check for empty result
        if (mysql_num_rows($result) > 0) {
 
            $result = mysql_fetch_array($result);
 
            $bet = array();
            $bet["betID"] = $result["betID"];
			$bet["value"] = $result["value"];
			$bet["bettorID"] = $result["bettorID"];
			$bet["acceptorID"] = $result["acceptorID"];
            // success
            $response["success"] = 1;
 
            // user node
            $response["bet"] = array();
 
            array_push($response["bet"], $bet);
 
            // echoing JSON response
            echo json_encode($response);
        } else {
            // no product found
            $response["success"] = 0;
            $response["message"] = "No bets found within range!";
 
            // echo no users JSON
            echo json_encode($response);
        }
    } else {
        // no product found
        $response["success"] = 0;
        $response["message"] = "No bets found within range!";
 
        // echo no users JSON
        echo json_encode($response);
    }
} else {
    // required field is missing
    $response["success"] = 0;
    $response["message"] = "Please supply a minimum and a maximum.";
 
    // echoing JSON response
    echo json_encode($response);
}
?>